package com.goods.shop.exam;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, String> inputMap = new HashMap<>();
        Set<String> sSet = new HashSet<>();

        while (true) {
            String nextLine = scanner.nextLine();
            if ("-1".equals(nextLine)) {
                break;
            }
            String[] split = nextLine.split("\\s+");
            String name = split[0];
            String oper = split[1];
            String code = split[2];
            if (name.startsWith("S")) {
                if (oper.equals("bind")) {
                    if (sSet.contains(name) || sSet.contains(code)) {
                        System.out.println(name + " " + oper + " fail");
                    } else {
                        inputMap.put(code, name);
                        sSet.add(name);
                        sSet.add(code);
                        System.out.println(name + " " + oper + " success");
                    }
                } else if (oper.equals("unbind")) {
                    if (!inputMap.containsKey(code) || !inputMap.get(code).equals(name)) {
                        System.out.println(name + " " + oper + " fail");
                    } else {
                        inputMap.remove(code);
                        sSet.remove(name);
                        sSet.remove(code);
                        System.out.println(name + " " + oper + " success");
                    }
                } else {
                    System.out.println("unknown command");
                }
            } else if (name.startsWith("U")) {
                if (oper.equals("scan")) {
                    if (inputMap.containsKey(code)) {
                        System.out.println(name + " pay to " + inputMap.get(code));
                    }else {
                        System.out.println(name + " " + oper + " fail");
                    }
                } else {
                    System.out.println("unknown command");
                }
            } else {
                System.out.println("unknown command");
            }
        }
        scanner.close();
    }
}
